package customview.ike.com.customviewproject.aop;

import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import customview.ike.com.customviewproject.R;
import customview.ike.com.customviewproject.aop.RequestPermission.RequestPermission;
import customview.ike.com.customviewproject.utils.permission.PermissionHelper;

/**
 *@author:ike
 *@function: 权限测试fragment
 *@creat time:11:51 2018/1/31
 **/

public class PermissionFragmnet extends Fragment{
    private static final int CODE_CAMERA = 0;
    private View rootView;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        rootView=View.inflate(getContext(), R.layout.activity_permission,null);
        return rootView;
    }
    @RequestPermission(value = android.Manifest.permission.CAMERA,requestCode =CODE_CAMERA )
    public void openCamera(View view){
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        startActivityForResult(intent,3);
    }

    @TargetApi(Build.VERSION_CODES.M)
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        PermissionHelper.getInstance().handleRequestPermissionsResult(requestCode,permissions,grantResults);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}
